package com.wanmait.schedule.controller;

import com.wanmait.schedule.entity.Classes;
import com.wanmait.schedule.entity.ClassesType;
import com.wanmait.schedule.entity.Teacher;
import com.wanmait.schedule.service.ClassesService;
import com.wanmait.schedule.service.ClassesTypeService;
import com.wanmait.schedule.service.TeacherService;
import com.wanmait.schedule.util.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 * 班级类型 前端控制器
 * </p>
 *
 * @author wanmait
 * @since 2022-12-05
 */
@RequestMapping("/manage/classesType")
@RestController
@RequiresPermissions("manage:classes")
public class ClassesTypeController {
        @Resource
        private ClassesTypeService classesTypeService;

        //添加
        @PostMapping("save")
        public AjaxResult save(@RequestBody ClassesType classesType, @RequestAttribute Teacher teacher){
                classesType.setInputId(teacher.getId());
                classesTypeService.save(classesType);
                return AjaxResult.success("添加成功");
        }

        //列表
        @GetMapping("list")
        public AjaxResult list(){
                return AjaxResult.success("成功",classesTypeService.list());
        }

        //修改
        @PostMapping("update")
        public AjaxResult update(@RequestBody ClassesType classesType){
                classesTypeService.updateById(classesType);
                return AjaxResult.success("成功");
        }

        //删除
        @GetMapping("delete")
        public AjaxResult delete(Integer id){
                classesTypeService.removeById(id);
                return AjaxResult.success("删除成功");
        }
}
